function inspection_game(alpha,lambda,bonus)
%initialize all variables
prisk=0.5;%assume random first choice
priskcorr=0.5;
compcash=0;
usercash=0;%money values
m=0;%variable to check if choice is repeated
reprate=0;%repetition rate
count=1;%number of choices
inspect=round(rand);%random first inspection
repcount=0;
w=0.15;
c=0.065;
p=0.5;
i=0.075;
C=0;I=0;
z=1;
n=0;%keep track of inspect

for t=1:200
    if inspect==1%inspection, 1st trial random(no algorithm)
        %update money amounts
        choice=input('1 or 0?','s');%ask for choice 1 is risky, 0 is safe
        if choice=='1'%update cash and tell user what happened based on choice
            display('i caught you.');
            usercash;
            compcash=compcash-i;
            choice=1;
        elseif choice=='0'
            display('keep up the good work.');
            usercash=usercash+(w-c);
            compcash=compcash+(p-w-i);
            choice=0;
        end

        %update probabilities and rep rate
        if choice=='1'%set c variable used in equation 7
            C=1;
        else
            C=0;
        end

        prisk=prisk+alpha*(C-prisk);%use equation 7

        if m==choice
            repcount=repcount+1;%update reprate if choice was repeated
            reprate=repcount/count;
        end

        reprateex=prisk^2+(1-prisk)^2;

        priskcorr=prisk+lambda*(reprateex-reprate);
        
        SDinspect=(1-priskcorr)*(p-w-i) + (priskcorr)*(-i);%inspect
        SDnotinspect=(1-priskcorr)*(p-w) + priskcorr*(-w);%notinspect
        SDemployer=SDinspect/(SDinspect+SDnotinspect)
        prob_inspect=1/(1+exp(-10*SDemployer+5))
        rand;
        if prob_inspect==0.5
            inspect=round(rand);
        elseif rand>=prob_inspect
            inspect=1;
        else
            inspect=0;
        end
        m=choice;
        n=inspect;
        workerchoice(t)=choice;
        employer_choice(t)=inspect;

    else %no inspection
        choice=input('1 or 0?','s');
        if choice=='1'
            display('no inspection, you got lucky.');
            usercash=usercash+w
            compcash=compcash-w
            choice=1;
        elseif choice=='0'
            display('no inspection');
            usercash=usercash+(w-c)
            compcash=compcash+(p-w)
            choice=0;
        end
        
        if m==choice
            repcount=repcount+1
            reprate=repcount/count;
        end
        
        if n==inspect
            priskcorr=priskcorr+bonus;
        end
        SDinspect=(1-priskcorr)*(p-w-i) + (priskcorr)*(-i);%inspect
        SDnotinspect=(1-priskcorr)*(p-w) + priskcorr*(-w);%notinspect
        SDemployer=SDinspect/(SDinspect+SDnotinspect)
        prob_inspect=1/(1+exp(-10*SDemployer+5))
        rand;
        if prob_inspect==0.5
            inspect=round(rand);
        elseif rand>=prob_inspect
            inspect=1;
        else
            inspect=0;
        end
        end
             n=inspect;
        workerchoice(t)=choice;
        employer_choice(t)=inspect;
        
    if t-20>0%plot of running avg. of choices
        runningwork(z)=sum(workerchoice(t-20:t)/20);
        runninginspect(z)=sum(employer_choice(t-20:t)/20);
        z=z+1;
    end
end
    count=count+1;
plot(runningwork)
hold on;
plot(runninginspect,'color','red')
ylim([0 1]);
hold on;
x=1:100;
y=i/w%equilibrium line for employee
plot(x,y)
hold on;
s=1:100;
t=c/w%equilibrium line for employer
plot(s,t)
usercash
compcash
end